home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / SOUND.SWG / 0029_Controling the PC Speaker.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  2KB  |  67 lines

  1. {
  2. SEAN PALMER
  3.  
  4. >I have TP 6.0, and I'am looking For a way to address my PC Speaker.  I don't
  5. >know what Port it is (like PORT[$30] or something), or how to send raw Sound
  6. >data to it. Could someone help me?
  7.  
  8. Try this, or actually a Variation on it. Doing VOC's and WAV's on a pc
  9. speaker is not an easy task...
  10.  
  11. What you're looking For is embedded in the 'click' Procedure below...
  12.  
  13. 'click' only works While no tone is being produced. click at different
  14. rates to get different pitches/effects.
  15.  
  16. so I guess the simple answer to your question is that it's controlled by
  17. bit 1 (from 0 to 7) of port $61.
  18. }
  19.  
  20. Unit uTone;
  21. Interface
  22.  
  23. Procedure tone(freq : Word);
  24. Procedure noTone;
  25. Procedure click;
  26.  
  27. Implementation
  28.  
  29. Const
  30.   sCntrl   = $61; { Sound control port }
  31.   SoundOn  = $03; { bit mask to enable speaker }
  32.   SoundOff = $FC; { bit mask to disable speaker }
  33.   C8253    = $43; { port address to control 8253 }
  34.   seTimer  = $B6; { tell 8253 to expect freq data next }
  35.   F8253    = $42; { frequency address on 8253 }
  36.  
  37. Procedure tone(freq : Word); Assembler;
  38. Asm
  39.   mov al, $B6
  40.   out $43, al  {Write timer mode register}
  41.   mov dx, $14
  42.   mov ax, $4F38
  43.   div freq     {1331000/Frequency pulse}
  44.   out $42, al
  45.   mov al, ah
  46.   out $42, al  {Write timer a Byte at a time}
  47.   in  al, $61
  48.   or  al, 3
  49.   out $61, al  {port B-switch speaker on}
  50. end;
  51.  
  52. Procedure noTone; Assembler;
  53. Asm
  54.   in  al, $61
  55.   and al, $FC
  56.   out $61, al
  57. end;
  58.  
  59. Procedure click; Assembler;
  60. Asm
  61.   in  al, $61
  62.   xor al, 2
  63.   out $61, al
  64. end;
  65.  
  66. end.
  67.